package com.zmn.oms.model.entity.perf;

import com.zmn.common.utils.pager.Pages;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * 权限查询实体
 *
 * @author hankangshuai
 * @date 2019/01/30 16:22
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class PermitQuery extends Pages implements Serializable {

    private static final long serialVersionUID = 1548836479775L;
    /**
     * 部门Id
     */
    private Integer loginDeptId;
    /**
     * 员工Id
     */
    private Integer loginStaffId;
    /**
     * 公司id
     */
    private Integer loginCompanyId;
    /**
     * 公司id
     **/
    private List<Integer> companyId;

    /**
     * 城市id
     **/
    private List<Integer> cityId;
    /**
     * 渠道ID
     **/
    private List<Integer> channelId;
    /**
     * 服务分类ID
     **/
    private List<Integer> servCategId;
    /**
     * 下单平台
     **/
    private List<Integer> plat;
    /**
     * 服务平台
     */
    private List<Integer> platWork;
    /**
     * 服务公司
     */
    private List<Integer> manageCompanyId;

    public BoolQueryBuilder getPermitEsBoolQueryBuilder() {
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        List<QueryBuilder> filter = boolQueryBuilder.filter();
        if (Objects.nonNull(getCompanyId())) {
            filter.add(QueryBuilders.termsQuery("companyId", getCompanyId()));
        }
        if (Objects.nonNull(getCityId())) {
            filter.add(QueryBuilders.termsQuery("cityId", getCityId()));
        }
        if (Objects.nonNull(getChannelId())) {
            filter.add(QueryBuilders.termsQuery("channelId", getChannelId()));
        }
        if (Objects.nonNull(getServCategId())) {
            filter.add(QueryBuilders.termsQuery("servCategId", getServCategId()));
        }
        if (Objects.nonNull(getPlat())) {
            filter.add(QueryBuilders.termsQuery("plat", getPlat()));
        }
        if (Objects.nonNull(getPlatWork())) {
            filter.add(QueryBuilders.termsQuery("platWork", getPlatWork()));
        }
        if (Objects.nonNull(getManageCompanyId())) {
            filter.add(QueryBuilders.termsQuery("manageCompanyId", getManageCompanyId()));
        }
        return boolQueryBuilder;
    }
}
